/* 将下面代码使用Promise的方式改进 */

// setTimeout(() => {
//   const a = 'hello';
//   setTimeout(() => {
//     const b = 'world';
//     setTimeout(() => {
//       const c = 'I love You';
//       console.log(a + b + c);
//     }, 10);
//   }, 10);
// }, 10);

// 方式一
{
  const getString = str => {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve(str);
      }, 10);
    });
  };

  getString('hello')
    .then(value => getString(value + 'world'))
    .then(value => getString(value + 'I love You'))
    .then(value => console.log('Type 1：' + value));
}

// 方式二
{
  const getString = async str => {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve(str);
      }, 10);
    });
  };

  const getResult = async () => {
    const a = await getString('hello');
    const b = await getString('world');
    const c = await getString('I love You');
    console.log('Type 2：' + a + b + c);
  };
  getResult();
}
